﻿<%@ Page Title="XML Test Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="XmlTestPage.aspx.cs" Inherits="XmlTestPage" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
<script type="text/javascript" src="Scripts/jquery-1.4.1.min.js"></script>
<script type="text/javascript" src="Scripts/Utility.as.js"></script>
<script type="text/javascript" src="Scripts/TestClass.as.js"></script>
<script type="text/javascript">
    var test = new Alex.Library.Web.Ajax.Samples.TestClass();
    test.Option.ReturnType = 'xml';
    test.Option.ErrorHandler = function (XMLHttpRequest, status) {
        alert(XMLHttpRequest.responseText);
    };
    function TestSave() {
        test.Option.RequestType = 'POST';
        var objs = [{ ID: 1, Name: "name1" }, { ID: 2, Name: "name2" }, { ID: 2, Name: "name22" }, { ID: 3, Name: "name3"}];
        test.SaveObjects(objs, function (data, textStatus, XMLHttpRequest) {
            alert(XMLHttpRequest.responseText);
        });
    };
    function TestGet() {
        test.Option.RequestType = 'GET';
        test.GetTestObjects({ ID: 2 }, function (data, textStatus, XMLHttpRequest) {
            alert(XMLHttpRequest.responseText);
            $(data).find('TestObject').each(function (i) {
                var $obj = $(this); //$(this) is TestObject Node
                alert($obj.find('Name').text());
            });
        });
    };
    function TestStaticMethod() {
        test.Option.RequestType = 'GET';
        test.TestStaticMethod(function (data, textStatus, XMLHttpRequest) {
            alert(XMLHttpRequest.responseText);
            var str = $(data).find('string');
            alert(str.text());
        });
    };
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
    <h2>
        使用XML作为返回值的DEMO
    </h2>
    <p>
        转到<a href="JsonTestPage.aspx" target="_self">JSON测试页面</a>
    </p>
    <p>
        转到<a href="AjaxScript.aspx" target="_self">Ajax脚本生成器页面</a>
    </p>
    <input type="button" value="TestSave" onclick="TestSave();" />
    <input type="button" value="TestGet" onclick="TestGet();" />        
    <input type="button" value="TestStaticMethod" onclick="TestStaticMethod();" />
</asp:Content>

